import Taro from '@tarojs/taro';

import {Command} from '../constant';
import {Dispatch} from 'typings';
import {IAllReducerProps} from '../types';
import {getReducerData} from '@/redux/store';
import {extraPathsValue} from '@/redux/util';

import api from 'api';

export default (dispatch: Dispatch) => {
  let action = {
    commonChange(...param: any) {
      dispatch({
        type: Command.commonChange,
        payload: extraPathsValue(...arguments),
      });
    },

    async escortsnatchorderAdd(escortTradeId) {
      //接单
      const params = {
        escortTradeId, //订单id
      };
      const result = await api.escortTradeController.escortsnatchorderAdd(params);
      if (result.code == 'K-000000') {
        Taro.showToast({
          title: '接单成功！',
          icon: 'none',
          duration: 2000,
        });
        setTimeout(() => {
          Taro.navigateTo({
            url: '/pages/package-D/lifeOrders/index?orderType=2',
          });
        }, 1000);
      } else {
        Taro.showToast({
          title: result.message,
          icon: 'none',
          duration: 2000,
        });
      }
    },
  };
  return action;
};

function getData(): IAllReducerProps {
  return {
    main: getReducerData('packageProxyDetailsDMain'),
  };
}
